home *** CD-ROM | disk | FTP | other *** search
/ World of Video / World of Video.iso / gfxprograms / 3dprograms / rayshade-4.0 / fixes / fix024 / libshade / yacc.y.diff < prev   
Text File  |  1995-02-13  |  14KB  |  413 lines

  1. *** yacc.y    Mon Oct 11 14:59:56 1993
  2. --- yacc.y.frac    Mon Oct 11 14:46:03 1993
  3. ***************
  4. *** 43,49 ****
  5.   #include "libobj/sphere.h"
  6.   #include "libobj/torus.h"
  7.   #include "libobj/triangle.h"
  8.   #include "liblight/point.h"
  9.   #include "liblight/infinite.h"
  10.   #include "liblight/spot.h"
  11. --- 43,52 ----
  12.   #include "libobj/sphere.h"
  13.   #include "libobj/torus.h"
  14.   #include "libobj/triangle.h"
  15. ! #include "libobj/ifs.h"
  16. ! #include "libobj/mountain.h"
  17. ! #include "libobj/fractalobject.h"
  18. ! #include "libobj/allocmatrix.h"
  19.   #include "liblight/point.h"
  20.   #include "liblight/infinite.h"
  21.   #include "liblight/spot.h"
  22. ***************
  23. *** 86,100 ****
  24. --- 89,114 ----
  25.   Atmosphere *CurEffect = (Atmosphere *)NULL;    /* Current atmos. effects */ 
  26.   PointList *Polypoints;                /* List of vertices */
  27.   MetaList *Metapoints, *Metapoint;
  28. + PointPool *Pointpool;
  29. + TrianglePool *Trianglepool;
  30. + EntityPool *Entitypool;
  31. + FractalEntity *CurrEntity;
  32. + FractalTriangle *CurrTriangle;
  33. + FractalPoint *CurrPoint;
  34. + int    count;
  35.   extern FILE *yyin;                /* input file pointer */
  36.   extern int yylineno;                /* Current line # in file */
  37.   extern Atmosphere *AtmosEffects;        /* atmospheric effects */
  38.   extern Medium TopMedium;            /* "air" */
  39. + static IfsOptions ifsOptions;                   /* options for IFS object */
  40. + static int ifsTransformRang;                    /* rang of IFS map */
  41.   extern void    GeomAddToDefined(),
  42.           LightAddToDefined(),
  43.           SurfaceAddToDefined();
  44.   extern Surface    *SurfaceGetNamed();
  45.   extern Geom     *GeomGetNamed();
  46. + int itemp;
  47.   %}
  48.   %union {
  49.       char *c;
  50. ***************
  51. *** 112,117 ****
  52. --- 126,139 ----
  53.       Trans *trans;
  54.       Expr *e;
  55.       SymtabEntry *sym;
  56. +     IfsTransList *translist;
  57. +         HeightValue   *heightvalues;
  58. +         StartGridStruct *startgrid;
  59. +         FractalClosure *fractalclosure;
  60. +         PointPool *Fpointpool;
  61. +         TrianglePool *Ftrianglepool;
  62. +         EntityPool *Fentitypool;
  63. +         TriangleList *Fentitytriangles;
  64.   }
  65.   %token <d> tFLOAT
  66.   %token <c> tSTRING tFILENAME
  67. ***************
  68. *** 132,137 ****
  69. --- 154,164 ----
  70.   %token tIMAGE tSMOOTH tCOMPONENT tTEXTSURF tRANGE tTILE tSTARTTIME tFRAMELENGTH
  71.   %token tNAME tFILTER tGAUSS tBODY tSAMPLE tEXTINCT tWINDY tMOUNT
  72.   %token tSHUTTER tFRAMES
  73. + %token tIFS tMINSIZE tMAXDEPTH tBOUNDING
  74. + %token tNORMALWEIGHTING tLOWPASS tHIGHPASS tCONSTANT 
  75. + %type <i> IfsNormalWeightingMethod
  76. + %token tMOUNTAIN
  77. + %token tFRACTALOBJECT tFPOINTS tFTRIANGLES tFENTITIES tENTITY
  78.   %type <c> Filename
  79.   %type <e> AnimExpr MExpr ParenExpr
  80.   %type <d> Expr Float
  81. ***************
  82. *** 152,158 ****
  83. --- 179,197 ----
  84.   %type <map> Mapping MapMethod OptMapping
  85.   %type <trans> TransformType
  86.   %type <sym> Symtabent
  87. + %type <obj> IfsCondensation IfsLeaves Ifs CIfs
  88. + %type <translist> IfsTransforms
  89. + %type <obj> Mountain
  90. + %type <obj> FractalObject
  91. + %type <heightvalues> HeightValues
  92. + %type <startgrid> StartGrid
  93. + %type <Fpointpool> FPointPool
  94. + %type <Ftrianglepool> FTrianglePool
  95. + %type <Fentitypool> FEntityPool
  96. + %type <Fentitytriangles> FEntityTriangles
  97. + %type <fractalclosure> FFractalClosure
  98.   
  99.   %left '+' '-'
  100.   %left '*' '/' '%'
  101.   %left UMINUS
  102. ***************
  103. *** 257,262 ****
  104. --- 296,305 ----
  105.           | Disc
  106.           | Torus
  107.           | Blob
  108. +         | Ifs
  109. +         | CIfs
  110. +                 | Mountain
  111. +                 | FractalObject
  112.           ;
  113.   NameObject    : tNAME tSTRING TransTextObj
  114.           {
  115. ***************
  116. *** 968,973 ****
  117. --- 1011,1181 ----
  118.               $$ = GeomHfCreate($2);
  119.           }
  120.           ;
  121. + Mountain        : tMOUNTAIN OptSurface Vec2d Vec2d Float Float Float Float Float StartGrid
  122. +                 {
  123. +                         $$ = GeomMountainCreate($3, $4, (int)$5, $6, (int)$7, (int)$8, $9, $10);
  124. +                         if ($$)
  125. +                             $$->surf = $2;
  126. +                 }
  127. +                 | tMOUNTAIN Vec2d Vec2d Float Float Float Float Float StartGrid
  128. +                 {
  129. +                         $$ = GeomMountainCreate($2, $3, (int)$4, $5, (int)$6, (int)$7, $8, $9);
  130. +                 }
  131. +                 ;
  132. + HeightValues    : HeightValues Float
  133. +                 {
  134. +                        $$ = (HeightValue *)Malloc(sizeof(HeightValue));
  135. +                        $$->Next  = $1;
  136. +                        $$->Value = $2;
  137. +                 }
  138. +                 | Float
  139. +                 {
  140. +                       $$ = (HeightValue *)Malloc(sizeof(HeightValue));
  141. +                       $$->Value = $1;
  142. +                       $$->Next  = NULL;
  143. +                 }
  144. +                 ;
  145. + StartGrid       : HeightValues
  146. +                 {
  147. +                        int    i,j,k;
  148. +                        HeightValue  *CurrHV, *CurrHV2;
  149. +                        for (i = 0, CurrHV = $1; CurrHV != NULL; CurrHV = CurrHV->Next, i++);
  150. +                        for (j = 1; j*j < i; j++);
  151. +                        if (j*j != i) RLerror(RL_ABORT, "Invalid number of startgridvalues: %d\n", i);
  152. +                        else {
  153. +                            $$ = (StartGridStruct *)share_malloc(sizeof(StartGridStruct));
  154. +                            if ($$) {
  155. +                                $$->Size = j-1;
  156. +                                CurrHV = $1;
  157. +                                $$->Data = AllocMatrix(Float, j, j);
  158. +                                for (i = 0; i < j; i++)
  159. +                                   for (k = 0; k < j; k++) {
  160. +                                         $$->Data[i][k] = CurrHV->Value;
  161. +                                         CurrHV2 = CurrHV;
  162. +                                         CurrHV = CurrHV->Next;
  163. +                                         free(CurrHV2);
  164. +                                   }
  165. +                            }
  166. +                        }
  167. +                 }
  168. +                 ;
  169. + FractalObject:  tFRACTALOBJECT OptSurface Float Float Float Float FFractalClosure
  170. +                 {
  171. +                    $$ = GeomFractalObjCreate((int)$3, $4, $5, $6, $7);
  172. +                    if ($$)
  173. +                        $$->surf = $2;
  174. +                 }
  175. +                 ;
  176. + FFractalClosure: FPointPool FTrianglePool FEntityPool
  177. +                 {
  178. +                     $$ = (FractalClosure *)share_malloc(sizeof(FractalClosure));
  179. +                     $$->Pointpool = $1;
  180. +                     $$->Trianglepool = $2;
  181. +                     $$->Entitypool = $3;
  182. +                 }
  183. +                 ;
  184. + FPointPool:  tFPOINTS 
  185. +              {
  186. +                 Pointpool = (PointPool *)share_malloc(sizeof(PointPool));
  187. +                 Pointpool->Points = (FractalPoint *)share_malloc(PointsToAllocate * sizeof(FractalPoint));
  188. +                 Pointpool->NumberOfPoints = 0;
  189. +                 Pointpool->PointsAllocated = PointsToAllocate;
  190. +              }
  191. +              FPoints
  192. +              {
  193. +                 $$ = Pointpool;
  194. +              }
  195. +              ;
  196. + FPoints:   FPoint
  197. +            {
  198. +            }
  199. +            | FPoint FPoints
  200. +            {
  201. +            }
  202. +            ;
  203. + FPoint:  Float Float Float
  204. +          {
  205. +              CheckPoints(Pointpool->Points, Pointpool->NumberOfPoints, Pointpool->PointsAllocated);
  206. +              CurrPoint = &Pointpool->Points[Pointpool->NumberOfPoints++];
  207. +              CurrPoint->x = $1;
  208. +              CurrPoint->y = $2;
  209. +              CurrPoint->z = $3;
  210. +          }
  211. +          ;
  212. + FTrianglePool:  tFTRIANGLES
  213. +              {
  214. +                 Trianglepool = (TrianglePool *)share_malloc(sizeof(TrianglePool));
  215. +                 Trianglepool->Triangles = (FractalTriangle *)share_malloc(TrianglesToAllocate * sizeof(FractalTriangle));
  216. +                 Trianglepool->NumberOfTriangles = 0;
  217. +                 Trianglepool->TrianglesAllocated = TrianglesToAllocate;
  218. +              }
  219. +              FTriangles
  220. +              {
  221. +                 $$ = Trianglepool;
  222. +              }
  223. +              ;
  224. + FTriangles: FTriangle
  225. +             {
  226. +             }
  227. +             | FTriangle FTriangles
  228. +             {
  229. +             }
  230. +             ;
  231. + FTriangle:  Float Float Float
  232. +             {
  233. +                 CheckTriangles(Trianglepool->Triangles, Trianglepool->NumberOfTriangles,
  234. +                                Trianglepool->TrianglesAllocated);
  235. +                 CurrTriangle = &Trianglepool->Triangles[Trianglepool->NumberOfTriangles++];
  236. +                 CurrTriangle->Point[0] = $1 - 1;
  237. +                 CurrTriangle->Point[1] = $2 - 1;
  238. +                 CurrTriangle->Point[2] = $3 - 1;
  239. +             }
  240. +             ;
  241. + FEntityPool:  tFENTITIES
  242. +              {
  243. +                 Entitypool = (EntityPool *)share_malloc(sizeof(EntityPool));
  244. +                 Entitypool->Entities = (FractalEntity *)share_malloc(EntitiesToAllocate * sizeof(FractalEntity));
  245. +                 Entitypool->NumberOfEntities = 0;
  246. +                 Entitypool->EntitiesAllocated = EntitiesToAllocate;
  247. +              } 
  248. +              FEntities
  249. +              {
  250. +                 $$ = Entitypool;
  251. +              } 
  252. +              ;
  253. + FEntities: FEntity
  254. +            {
  255. +            }
  256. +            | FEntity FEntities
  257. +            {
  258. +            }
  259. +            ;
  260. + FEntity:  tENTITY Float Float Float FEntityTriangles
  261. +           {
  262. +               CheckEntities(Entitypool->Entities, Entitypool->NumberOfEntities,
  263. +                                Entitypool->EntitiesAllocated);
  264. +               CurrEntity = &Entitypool->Entities[Entitypool->NumberOfEntities++];
  265. +               CurrEntity->XSize = $2;
  266. +               CurrEntity->YSize = $3;
  267. +               CurrEntity->ZSize = $4;
  268. +               CurrEntity->Triangles = $5;
  269. +           }
  270. +           ;
  271. + FEntityTriangles: Float
  272. +                   {
  273. +                       $$ = (TriangleList *)share_malloc(sizeof(TriangleList));
  274. +                       $$->TriangleNumber = $1 - 1;
  275. +                       $$->Next = NULL;
  276. +                   }
  277. +                   | FEntityTriangles Float
  278. +                   {
  279. +                       $$ = (TriangleList *)share_malloc(sizeof(TriangleList));
  280. +                       $$->TriangleNumber = $2 - 1;
  281. +                       $$->Next = $1;
  282. +                   }
  283. +                   ;
  284.   Poly        : tPOLY OptSurface Polypoints
  285.           {
  286.               $$ = GeomPolygonCreate(Polypoints, Npoints,
  287. ***************
  288. *** 1186,1191 ****
  289. --- 1394,1511 ----
  290.               Metapoint->next = Metapoints;
  291.               Metapoints = Metapoint;
  292.               Npoints++;
  293. +         }
  294. +         ;
  295. + Ifs        : IfsKey OptSurface IfsTransforms IfsOptions tEND
  296. +         {
  297. +             $$ = GeomIfsCreate($3, &ifsOptions);
  298. +             if ($$) 
  299. +                 $$->surf = $2;
  300. +         }
  301. +         ;
  302. + CIfs        : IfsKey OptSurface IfsCondensation IfsLeaves IfsTransforms IfsOptions tEND
  303. +         {
  304. +             $$ = GeomCIfsCreate($5, $3, $4, &ifsOptions);
  305. +             if ($$) 
  306. +                 $$->surf = $2;
  307. +         }
  308. +         ;
  309. + IfsKey          : tIFS  /* set option defaults */
  310. +                 {
  311. +                         ifsTransformRang = 1;
  312. +                         ifsOptions.depth = 99999999;
  313. +                         ifsOptions.size = 0.;
  314. +                         ifsOptions.normalweighting = HIGHPASS_NORMAL_WEIGHTING;
  315. +             ifsOptions.boxbounding = ifsOptions.spherebounding = FALSE;
  316. +             ifsOptions.listfilename = NULL;
  317. +                 }
  318. +                 ;
  319. + IfsCondensation    : TransTextObj ','
  320. +         {
  321. +             $$ = $1;
  322. +         }
  323. +         ;
  324. + IfsLeaves       : TransTextObj ',' /* Oppenheimer trees */
  325. +                 {
  326. +                         $$ = $1;
  327. +                 }
  328. +                 | /* no leaves -> a true IFS */
  329. +                 {
  330. +                         $$ = (Geom *)NULL;
  331. +                 }
  332. +                 ;
  333. + IfsTransforms    : OptIfsTransformRang IfsTransform
  334. +         {
  335. +             $$ = (IfsTransList *)Malloc(sizeof(IfsTransList));
  336. +             $$->trans = TransHead;
  337. +             $$->transtail = TransTail;
  338. +             $$->next = (IfsTransList *)NULL;
  339. +                         $$->rang = ifsTransformRang;
  340. +         }
  341. +         | IfsTransforms ',' OptIfsTransformRang IfsTransform
  342. +         {
  343. +             $$ = (IfsTransList *)Malloc(sizeof(IfsTransList));
  344. +             $$->trans = TransHead;
  345. +             $$->transtail = TransTail;
  346. +             $$->next = $1;
  347. +                         $$->rang = ifsTransformRang;
  348. +         }
  349. +         ;
  350. + IfsTransform    : TransformType
  351. +         {
  352. +             TransHead = TransTail = $1;
  353. +         }
  354. +         | IfsTransform PostTransform
  355. +         ;
  356. + OptIfsTransformRang : IExpr
  357. +                 {
  358. +                         ifsTransformRang = $1;
  359. +                 }
  360. +                 | /* no rang specified */
  361. +                 ;
  362. + IfsOptions      : /* no options */
  363. +                 | IfsOptions tMINSIZE Expr
  364. +                 {
  365. +                         ifsOptions.size = $3;
  366. +                 }
  367. +                 | IfsOptions tMAXDEPTH IExpr
  368. +                 {
  369. +                         ifsOptions.depth = $3;
  370. +                 }
  371. +                 | IfsOptions tNORMALWEIGHTING IfsNormalWeightingMethod
  372. +                 {
  373. +                         ifsOptions.normalweighting = $3;
  374. +         }
  375. +         | IfsOptions tBOUNDING IfsBoundingVolumeType
  376. +         {
  377. +         }
  378. +         | IfsOptions tLIST Filename
  379. +         {
  380. +             ifsOptions.listfilename = strsave($3);
  381. +         }
  382. +                 ;
  383. + IfsNormalWeightingMethod: tCONSTANT
  384. +                 {
  385. +                         $$ = CONSTANT_NORMAL_WEIGHTING;
  386. +                 }
  387. +                 | tLOWPASS
  388. +                 {
  389. +                         $$ = LOWPASS_NORMAL_WEIGHTING;
  390. +                 }
  391. +                 | tHIGHPASS
  392. +                 {
  393. +                         $$ = HIGHPASS_NORMAL_WEIGHTING;
  394. +                 }
  395. +                 ;
  396. + IfsBoundingVolumeType:    tBOX
  397. +         {
  398. +             ifsOptions.boxbounding = TRUE;
  399. +             ifsOptions.spherebounding = FALSE;
  400. +         }
  401. +         | tSPHERE
  402. +         {
  403. +             ifsOptions.boxbounding = FALSE;
  404. +             ifsOptions.spherebounding = TRUE;
  405.           }
  406.           ;
  407.   Outfile        : tOUTFILE Filename
  408.